/*
 *  Copyright 2004 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.persistence.core;

import com.blandware.atleap.common.util.PartialCollection;
import com.blandware.atleap.common.util.QueryInfo;
import com.blandware.atleap.model.core.Layout;
import com.blandware.atleap.persistence.exception.DeleteException;
import com.blandware.atleap.persistence.exception.UpdateException;

/**
 * <p>DAO for layout</p>
 * <p><a href="LayoutDAO.java.html"><i>View Source</i></a></p>
 *
 * @author Sergey Zubtsovskiy <a href="mailto:sergey.zubtsovskiy@blandware.com">&lt;sergey.zubtsovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.10 $ $Date: 2007/04/07 13:04:58 $
 */
public interface LayoutDAO extends LocalizableDAO {
	// ~ CRUD Methods ================================================================

	/**
	 * Creates new layout
	 *
	 * @param layout Value object that represents what layout must be created
	 * @return ID of created layout
	 */
	public Long createLayout(Layout layout);

	/**
	 * Retrieves layout with specified ID
	 *
	 * @param layoutId ID to search by
	 * @return Layout or null if no layout with specified ID exists in database
	 */
	public Layout retrieveLayout(Long layoutId);

	/**
	 * Updates layout
	 *
	 * @param layout Layout to update
     * @throws com.blandware.atleap.persistence.exception.UpdateException Thrown
     * if update is invalid
	 */
	public void updateLayout(Layout layout) throws UpdateException;

	/**
	 * Deletes layout
	 *
	 * @param layout Layout to delete
	 * @throws DeleteException if layout cannot be deleted (e.g. there is one or more content page
	 *                         based on it)
	 */
	public void deleteLayout(Layout layout) throws DeleteException;

	// ~ Additional methods ================================================================

	/**
	 * Retrieves filtered/sorted collection of layouts.
	 *
	 * @param queryInfo Object that contains information about how to filter and sort data
	 * @return Collection of layouts
	 */
	public PartialCollection listLayouts(QueryInfo queryInfo);

	/**
	 * Searches for duplicates. Returns true if there is one or more layouts with another ID, but which
	 * have same values from some set (e.g. name and/or definition)
	 *
	 * @param layout Layout to find duplicates for
	 * @return whether this layout has duplicates
	 */
	public boolean hasDuplicates(Layout layout);

	// ~ Finders ================================================================

	/**
	 * Finds layout by content page URI
	 *
	 * @param contentPageUri URI of content page to find layout
	 * @return Layout or null if nothing was found
	 */
	public Layout findLayoutByContentPageUri(String contentPageUri);

	/**
	 * Finds layout by name of Struts tile definition name
	 *
	 * @param definitionName Name of defintion to search by
	 * @return Layout or null if nothing was found
	 */
	public Layout findLayoutByDefinition(String definitionName);

	/**
	 * Finds layout by name
	 *
	 * @param name Name of layout to search by
	 * @return Layout or null if nothing was found
	 */
	public Layout findLayoutByName(String name);

}
